<?php
include_once 'basepath.php';
/*
 * data arrive
 * $level,$lyear,$ltours,$selectyear
 */
//print_r($ltours);
//print_r($listbus);
//print_r($level)
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" href="<?php echo $bpath;?>/css/reset.css" />
<link rel="stylesheet" href="<?php echo $bpath;?>/css/text.css" />
<link rel="stylesheet" href="<?php echo $bpath;?>/css/960_24_col.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/jquery-ui-1.8.21.custom.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/style.css" />
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery-1.7.2.min.js"></script>
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="<?php echo $bpath;?>/js/scripts.js"></script>
<script>
$(function(){
	$( ".list" ).accordion({ header: 'h3',autoHeight: true, active: false,autoHeight:false,collapsible:true,
	change:function(event,ui){
							var idtourid=ui.newHeader.attr("id");
							if(idtourid!=undefined){
						var idtour=idtourid.replace("t_","");
							 $.ajax({
						            url: "index.php?liste/getlcountchambre/"+idtour,
						            type:'POST',
						            dataType: 'json',
						            success: function(output_string){
										
										for( os in output_string)
										{
											var strtext="";
											var total=0;	
											var divp=$("#chambbybus_"+os)
											divp.text("");
											for (ch in output_string[os])
												{
													if(ch==1)	{ strtext+=output_string[os][1]+"/s&nbsp;";total+=parseInt(output_string[os][1]);}					
													if(ch==2)	{ strtext+=output_string[os][2]+"/d&nbsp;";total+=parseInt(output_string[os][2]);	}	
													if(ch==3)	{ strtext+=output_string[os][3]+"/t&nbsp;";total+=parseInt(output_string[os][3]);}		
													if(ch==4)	{ strtext+=output_string[os][4]+"/q&nbsp;";total+=parseInt(output_string[os][4]);}			
												}
													strtext+="<br/>total::"+total+"&nbsp;chambres"
													//alert(output_string[os]);
													divp.append(strtext);

										}	
						            }
										});//ajax

			//get place info					
									$.ajax({
						            url: "index.php?liste/getplaceinfo/"+idtour,
						            type:'POST',
						            dataType: 'json',
						            success: function(output_string){
										
						            	for( pi in output_string)
						            		{
													//alert(output_string[pi]["seatavaible"]+"/"+output_string[pi]["seatqty"]);
												$("#bus_"+pi).text(output_string[pi]["seatavaible"]+"/"+output_string[pi]["seatqty"])
	
						            		}

										
						            	}
										});//ajax
	
							}//idtour undifined
	}});//accordion

//add xiaoming 2012-12-31 for display total people by un tours	
				$(".totalshow").hover(
							function(event)
								{

								var idtourid=$(this).parent().attr("id");
								if(idtourid!=undefined)
								{
									var idtour=idtourid.replace("t_","");
		
										$.ajax({
								            url: "index.php?liste/getplaceinfo/"+idtour,
								            type:'POST',
								            dataType: 'json',
								            success: function(output_string){
												
												var total=0;
								            	for( pi in output_string)
								            		{
															//alert(output_string[pi]["seatavaible"]+"/"+output_string[pi]["seatqty"]);
														var bustoal=output_string[pi]["seatqty"]-output_string[pi]["seatavaible"];
														total=total+bustoal;
														
			
								            		}
		
								            	//alert($(this).parent().attr("id"));
								            	$("#t_"+idtour).find(".numbertotal").html(total+" People(s) reserved");
								            	event.stopPropagation();
								            	
								            	}
												});//ajax
											
								}
								},
							function()
								{
									$(".numbertotal").html("");
								}	


						);//end hover
	

	
})
</script>
</head>

<body>
	<div class="principal container_24">
		
		<!--logo-->
		<div class="logo grid_24">
			<div class="grid_1">&nbsp;</div>
			<div class="grid_4 logoimage"><img src="<?php echo $bpath;?>/img/logo.png" height="90"></div>
			<div class="logout grid_5"><a href="index.php?loginprocess/loginout"><img src="<?php echo $bpath;?>/img/bt_logout.jpg"/></a></div>
		</div><!-- end logo-->
		
		<!--menupricipal-->
		<div class="menuprincipal grid_24">
			<?php 
			foreach($lyear as $ly)
			{	
				if($ly["year"]==$selectyear)
				{
				?>
					<span class="yearselected"><?php echo $ly["year"]?></span>
				<?php }else{?>
			<a  class ="yearlist " href="index.php?liste/listtour/<?php echo $ly["year"];?>"><?php echo $ly["year"]?></a>
			<?php }}?>
		</div>
		<!-- end menupricipal-->
				
			<div class="descprincipal grid_22">
				description
			</div>
			
			<div class="grid_24 listcontent">
				<h1>THE TOUR LIST</h1>
				<div class="grid_22 list">
				
					 <?php foreach ($ltours as $tours){?>	 
					<h3 id="t_<?php echo $tours["idtours"]; ?>"><?php echo strtoupper($tours["code"]);?><span class="totalshow" style="padding-left: 50px;font-size:60%;color:red;">[Total]</span><span class="numbertotal" style="padding-left: 20px;font-size:70%;color:red;"></span></span></h3>
					<div>
					<?php if($level =="admin"){?>
					 <div class="s_edit_tour grid_20">
						 	<label>Edit This Tour Information</label>
						 	<!--<form action="" method="post" style="display:inline-block;">
							<input type="submit" name="delet" value="Delete" >
							</form>-->
							
							<form action="index.php?edit/edittours" method="post"  style="display:inline-block;">
							<input type="hidden" name="idtour" value="<?php echo $tours["idtours"]; ?>" >
							<input type="submit" name="Edit" value="Edit" >
							</form>
							<form action="index.php?add/addbus" method="post"  style="display:inline-block;">
							<input type="hidden" name="fk_idtours" value="<?php echo $tours["idtours"]?>">
							<input type="submit" name="addnewbus" value="Add New Bus" >
							</form>
						 </div>
					<?php }?>	
						
						<?php 
							$id_tour_ltour=$tours["idtours"];
							$arr_bus_info=$listbus["$id_tour_ltour"];
							foreach ($arr_bus_info as $abusinfo)
							{
						?> 	
						<div class="businfo grid_5">
					  	<a href="index.php?add/addbooking/<?php echo $abusinfo["idbus"]; ?>/<?php echo $id_tour_ltour;?>">#&nbsp;<?php  echo $abusinfo["code"];?></a><span class="placelibre" id="bus_<?php echo $abusinfo["idbus"]; ?>"><?php  echo $abusinfo["seatavaible"] ?>/<?php echo $abusinfo["seatqty"]; ?></span>
					  	<p id="chambbybus_<?php echo  $abusinfo["idbus"]; ?>">
					  		<!--0/s  2/d 5/t  6/q<br/>total::13 chambre -->
					  	</p>
						
						<form action="index.php?liste/listdetail/<?php echo $abusinfo["idbus"]?>/<?php echo $id_tour_ltour;?>" method="post">
								<input type="submit" name="detaillist" value="Detail List" >
						</form>
							<?php if($level =="admin"){?>
						<form action="index.php?edit/editbus" method="post">
							<input type="hidden" name="idbus" value="<?php echo  $abusinfo["idbus"]; ?>" >
							<input type="submit" name="Edit" value="Edit" >
						</form>
						<?php }?>
						

						</div><!--end businfo-->	
						 <?php } // foreach bus?>
				 
					</div>
					 <br/>
					 <?php }?>
					 <?php if($level =="admin"){?>
					<form  action="index.php?add/addtour" method="post">
						<input type="submit" value="Add New Tour" name="addnewtour">
					</form>
					
					<a href="index.php?liste/listuser">.</a>&nbsp;&nbsp;&nbsp;
					<a href="index.php?webctrl/web_adminmenu">Web Admin</a>
					 <?php }?>
				</div>
				
			</div>
	
		
	</div><!--end principal-->
</body>
</html>